// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <gtest/gtest.h>
#include <pollux/common/config/config.h>
#include <pollux/connectors/hive/hive_connector_split.h>

using namespace kumo::pollux;
using namespace kumo::pollux::connector::hive;

TEST(HiveSplitTest, builder) {
  FileProperties properties = {.fileSize = 11, .modificationTime = 1111};
  auto extra = std::make_shared<std::string>("extra file info");
  std::unordered_map<std::string, std::string> custom;
  custom["custom1"] = "customValue1";
  std::unordered_map<std::string, std::string> serde;
  serde["serde1"] = "serdeValue1";
  auto split = HiveConnectorSplitBuilder("filepath")
                   .start(100)
                   .length(100000)
                   .splitWeight(1)
                   .fileFormat(dwio::common::FileFormat::DWRF)
                   .infoColumn("info1", "infoValue1")
                   .partitionKey("DS", "2024-11-01")
                   .tableBucketNumber(11)
                   .customSplitInfo(custom)
                   .extraFileInfo(extra)
                   .serdeParameters(serde)
                   .connectorId("connectorId")
                   .fileProperties(properties)
                   .build();

  EXPECT_EQ(100, split->start);
  EXPECT_EQ(100000, split->length);
  EXPECT_EQ(1, split->splitWeight);
  EXPECT_TRUE(dwio::common::FileFormat::DWRF == split->fileFormat);
  EXPECT_EQ("infoValue1", split->infoColumns["info1"]);
  auto it = split->partitionKeys.find("DS");
  EXPECT_TRUE(it != split->partitionKeys.end());
  EXPECT_EQ("2024-11-01", it->second.value());
  EXPECT_EQ(11, split->tableBucketNumber.value());
  EXPECT_EQ("customValue1", split->customSplitInfo["custom1"]);
  EXPECT_EQ(std::string("extra file info"), *split->extraFileInfo);
  EXPECT_EQ("serdeValue1", split->serdeParameters["serde1"]);
  EXPECT_EQ("connectorId", split->connectorId);
  EXPECT_EQ(
      properties.fileSize.value(), split->properties.value().fileSize.value());
  EXPECT_EQ(
      properties.modificationTime.value(),
      split->properties.value().modificationTime.value());
}
